import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'audititemName',
    label: '审核项名称',
  },
  {
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.AUDIT_OBJECT_TYPE 便于维护
      options: getDictOptions('audit_object_type'),
    },
    fieldName: 'auditObject',
    label: '审核对象',
  },
  {
    component: 'Input',
    fieldName: 'auditChapter',
    label: '审核章节',
  },
  {
    component: 'Input',
    fieldName: 'audititemContent',
    label: '审核项内容',
  },
  {
    component: 'Textarea',
    fieldName: 'audititemPrompt',
    label: '审核项提示词',
  },
  {
    component: 'Select',
    componentProps: {
    },
    fieldName: 'auditType',
    label: '审核类别',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_YES_NO 便于维护
      options: getDictOptions('sys_yes_no'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'status',
    label: '状态',
  },
  {
    component: 'Input',
    fieldName: 'createBy',
    label: '创建者',
  },
  {
    component: 'Textarea',
    fieldName: 'createDept',
    label: '创建部门',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '审核项ID',
    field: 'id',
  },
  {
    title: '审核项名称',
    field: 'audititemName',
  },
  {
    title: '审核对象',
    field: 'auditObject',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.AUDIT_OBJECT_TYPE 便于维护
        return renderDict(row.auditObject, 'audit_object_type');
      },
    },
  },
  {
    title: '审核章节',
    field: 'auditChapter',
  },
  {
    title: '审核项内容',
    field: 'audititemContent',
  },
  {
    title: '审核项提示词',
    field: 'audititemPrompt',
  },
  {
    title: '审核类别',
    field: 'auditType',
  },
  {
    title: '状态',
    field: 'status',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_YES_NO 便于维护
        return renderDict(row.status, 'sys_yes_no');
      },
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    label: '审核项ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '审核项名称',
    fieldName: 'audititemName',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '审核对象',
    fieldName: 'auditObject',
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.AUDIT_OBJECT_TYPE 便于维护
      options: getDictOptions('audit_object_type'),
    },
    rules: 'selectRequired',
  },
  {
    label: '审核章节',
    fieldName: 'auditChapter',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '审核项内容',
    fieldName: 'audititemContent',
    component: 'RichTextarea',
    componentProps: {
      // options: {
      //  readyonly: false, // 是否只读
      // }
      // width: '100%', // 宽度
      // showImageUpload: true, // 是否显示图片上传
      // height: 400 // 高度 默认400
    },
    rules: 'required',
  },
  {
    label: '审核项提示词',
    fieldName: 'audititemPrompt',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '审核类别',
    fieldName: 'auditType',
    component: 'Select',
    componentProps: {
    },
    rules: 'selectRequired',
  },
  {
    label: '状态',
    fieldName: 'status',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_YES_NO 便于维护
      options: getDictOptions('sys_yes_no'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
];
